#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include "chartview.h"
#include "mywidget.h"
#include <QDebug>
MyWidget::MyWidget()
{
    ChartView *chartView = new ChartView();
    QHBoxLayout *layout = new QHBoxLayout;
    QWidget *right_frame=new QWidget;
    QPushButton *refresh=new QPushButton;
    refresh->setText("刷新");
    QPushButton *casuale=new QPushButton;
    casuale->setText("生成随机数");
    QVBoxLayout *right_layout=new QVBoxLayout;
    QHBoxLayout *right_down_casuale_layout=new QHBoxLayout;
    QLabel *down_casuale=new QLabel;
    down_casuale->setText("随机数下限：");
    down_lineedit=new QLineEdit;
    down_lineedit->setMinimumWidth(100);
    right_down_casuale_layout->addWidget(down_casuale);
    right_down_casuale_layout->addWidget(down_lineedit);
    QLabel *up_casuale=new QLabel;
    up_casuale->setText("随机数上限：");
    up_lineedit=new QLineEdit;
    up_lineedit->setMinimumWidth(100);
    QHBoxLayout *right_up_casuale_layout=new QHBoxLayout;

    QHBoxLayout *right_count_casuale_layout=new QHBoxLayout;
    QLabel *count_label=new QLabel;
    count_label->setText("生成的随机数个数：");
    count_lineedit=new QLineEdit;

    QHBoxLayout *right_K_counr_layout=new QHBoxLayout;
    QLabel *K_label=new QLabel;
    K_label->setText("簇的个数：");
    K_lineedit=new QLineEdit;

    right_K_counr_layout->addWidget(K_label);
    right_K_counr_layout->addWidget(K_lineedit);

    right_count_casuale_layout->addWidget(count_label);
    right_count_casuale_layout->addWidget(count_lineedit);
    right_up_casuale_layout->addWidget(up_casuale);
    right_up_casuale_layout->addWidget(up_lineedit);
    right_layout->addLayout(right_down_casuale_layout);
    right_layout->addLayout(right_up_casuale_layout);
    right_layout->addLayout(right_count_casuale_layout);
    right_layout->addWidget(casuale);
    right_layout->addLayout(right_K_counr_layout);
    right_layout->addWidget(refresh);


    right_frame->setLayout(right_layout);


    layout->addWidget(chartView,4);
    layout->addWidget(right_frame,1);

    connect(casuale,SIGNAL(clicked(bool)),this,SLOT(RandomClick()));
    connect(this,SIGNAL(setRandom(int,int,int)),chartView,SLOT(setRandom(int,int,int)));
    connect(refresh,SIGNAL(clicked(bool)),this,SLOT(Refresh()));
    connect(this,SIGNAL(_refresh_(int)),chartView,SLOT(Refresh(int)));

    window.setLayout(layout);
    window.resize(1000, 800);
    window.show();
}


void MyWidget::RandomClick()
{
    //qDebug()<<"hhhh";
    emit setRandom(up_lineedit->text().toInt(),down_lineedit->text().toInt(),count_lineedit->text().toInt());
}

void MyWidget::Refresh()
{
    //qDebug()<<"re!";

    emit _refresh_(K_lineedit->text().toInt());
}
